package com.qmds.config;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class OpenFeignConfig implements RequestInterceptor {

    // 拦截请求,设置请求头
    @Override
    public void apply(RequestTemplate template) {
        //1.获取
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        //2.设置
        template.header("Token", request.getHeader("Token"));
    }

}
